package com.lqg.bookLibrary.service.recommend;


import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lqg.bookLibrary.pojo.AvgScore;
import com.lqg.bookLibrary.pojo.Books;
import com.lqg.bookLibrary.pojo.Users;
import com.lqg.bookLibrary.service.IAvgScoreService;
import com.lqg.bookLibrary.service.IBooksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ThermalRecommend {

    @Autowired
    private IBooksService booksService;

    @Autowired
    private IAvgScoreService avgScoreService;

    public List<Books> latest() {
        List<Books> list1 =
                booksService.lambdaQuery().orderByDesc(Books::getCreatedAt).last("limit 5").list();
        return list1;
    }

    public List<Books> hottest() {
        List<AvgScore> list1 =
                avgScoreService.lambdaQuery().orderByDesc(AvgScore::getAvgScore).last("limit 5").list();
        List<Books> list = booksService.lambdaQuery().in(Books::getBookId,
                list1.stream().map(x -> x.getBookId()).collect(Collectors.toList())).list();
        return list;
    }

}
